package com.nb.hdj.testCase.permissionModule;

import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

/**
 * @Description: TODO
 * @Author: hedongjia
 * @Date: 2021/12/15 下午7:27
 * @Version: v1.0
 */
public class ViewRoleCase extends PermissionCaseBase{
    //输入角色内容
    private String roleName="自动化测试角色";
    /**
     * 查看角色数据测试用例
     * @param driver
     * @return
     */
    public boolean viewRole(WebDriver driver){
        try {
            //点击权限管理
            Thread.sleep(1500);
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("menuElement")));
            //点击角色管理
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("roleMenuElement")));
            //判断第一行角色名称是否有值
            if(!seleniumUtil.elementTextIsEqual(driver,By.xpath(permissionMap.get("firstRoleName")),"")){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 添加角色
     * @param driver
     * @return
     */
    public boolean insertRole(WebDriver driver){
        try {
            //点击添加角色
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("insertRoleButtonElement")));
            //输入角色名称
            seleniumUtil.elementClickAndClearAndInput(driver,By.xpath(permissionMap.get("inputRoleNameElement")),roleName);
            //选择权限 点击咨询
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("consultPermission")));
            //点击精品图库
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("photoPermission")));
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("determineButtonElement")));
            Thread.sleep(1000);
            if(seleniumUtil.elementTextIsContains(driver,By.xpath(permissionMap.get("firstRoleName")),roleName)){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    public boolean updateRole(WebDriver driver){

        try {
            //点击修改按钮
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("roleUpdateElement")));
            //输入角色名称
            roleName="更改自动化测试角色";
            seleniumUtil.elementClickAndClearAndInput(driver,By.xpath(permissionMap.get("inputRoleNameElement")),roleName);
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("determineButtonElement")));
            Thread.sleep(1000);
            if(seleniumUtil.elementTextIsContains(driver,By.xpath(permissionMap.get("firstRoleName")),roleName)){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 删除角色
     * @param driver
     * @return
     */
    public boolean deleteRole(WebDriver driver){
        try {
            //点击删除按钮
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("roleDeleteElement")));
            //点击确定
            seleniumUtil.elementClick(driver, By.xpath(permissionMap.get("roleDeleteYesElement")));
            Thread.sleep(1000);
            //判断是否删除  刚新增的角色
            if(!seleniumUtil.elementTextIsContains(driver,By.xpath(permissionMap.get("firstRoleName")),roleName)){
                return true;
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return false;
    }

}
